#include<bits/stdc++.h>//I will do better next time.
#define pb push_back
using namespace std;
typedef int I;
typedef long long LL;
const I N = 1e5 + 10;
I tc,n,m,a[N],ta[N]c[N],x[4],ans[N];
void solve(){
    for(I i = 0;i < 3;i++){
        scanf("%d",&x[i]);
    }
    for(I i = 1;i <= n;i++){
        ta[i] = a[i] ^ x[i % 4];
    }
    I tn = n,ct = 0;
    while(tn){
        tn >>= 1;
        ct++;
    }
    tn = 1;
    for(I i = 1;i <= ct;i++){
        tn *= 2;
    }
    for(I i = 1;i <= ct;i++){
        char s[N];
        scanf("%s",s + 1);
    }
    printf("%d\n",rand());
}
void Qingkong(){

}
I main(){
    freopen("arena.in","r",stdin);
    freopen("arena.out","w",stdout);
    scanf("%d%d",&n,&m);
    for(I i = 1;i <= n;i++){
        scanf("%d",&a[i]);
    }
    for(I i = 1;i <= m;i++){
        scanf("%d",&c[i]);
    }
    scanf("%d",&tc);
    for(;tc--;){
        solve();
    }
    return 0;
}

